package com.hsytech.baoinbao.waste;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.android.volley.VolleyError;
import com.hsytech.baoinbao.AdapterListView;
import com.hsytech.baoinbao.R;
import com.hsytech.baoinbao.SharedPreferencesTools;
import com.hsytech.baoinbao.base.BaseActivity;
import com.hsytech.baoinbao.gsondata.GsonUtil;
import com.hsytech.baoinbao.gsondata.RecyclingManStockData;
import com.hsytech.baoinbao.volleytool.ApiUrls;
import com.hsytech.baoinbao.volleytool.HttpUtil;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by 123 on 2016/3/11.
 */
public class WasteStorageActivity extends BaseActivity {
    private LinearLayout home_next;
    private EditText phone;
    private HttpUtil.HttpCallback httpCallback = new HttpUtil.HttpCallback() {
        @Override
        public void onSuccess(int what, JSONObject response) {
            Intent intent = new Intent(WasteStorageActivity.this, ListWasteActivity.class);
            intent.putExtra("phone", phone.getText().toString());
            startActivity(intent);
        }

        @Override
        public void onError(int what, int type, VolleyError error) {
            showToast(R.string.msg_http_failure);
        }

        @Override
        public void onErrorMsg(int what, String msg) {
            showToast(msg);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_waste_storage);
        setCenterTitleText("废品入库");
        setLeft_button(true);
        home_next = F(R.id.home_next);
        phone = F(R.id.phone);
        home_next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (phone.getText().toString().equals("")) {

                    showToast("请填写帐号");
                } else {

                    Map<String, String> data = new HashMap<>();
                    data.put("token", SharedPreferencesTools.getTOKEN(WasteStorageActivity.this));
                    data.put("user_name_re", phone.getText().toString());
                    HttpUtil.httpGetWithParams(0, ApiUrls.RECYCLING_MAN_STOCK + "?user_name_re=" + phone.getText().toString() + "&token=" + SharedPreferencesTools.getTOKEN(WasteStorageActivity.this), data, httpCallback, WasteStorageActivity.this);


                }
            }
        });
    }
}
